#pragma once
#include <iostream>
#include <string>
#include <deque>
#include <thread>
#include <mutex>
#include "Game.h"
using namespace std;



class Player
{
private:
	string name;
	int posX, posY;
	deque<char> *Inputqueue;
	bool StandardControls;
public:

	Player()
	{
		this->name = "";
		this->posX, posY = 0;
	}
	Player(string name, int posX, int posY, deque<char> *queue,bool controls)
	{
		this->name = name;
		this->posX = posX;
		this->posY = posY;
		this->Inputqueue = queue;
		this->StandardControls = controls;
	}
	void operator()()
	{
		while (1)
		{
			mutex_cout.lock();
			

			if (Inputqueue->empty() == false)
			{
				Position position;
				position.name = this->name;
				position.prevX = this->posX;
				position.prevY = this->posY;

				if (StandardControls)
				{
					if (Inputqueue->front() == 'a')
					{
						if (posX > 11)
							posX--;
					}
					if (Inputqueue->front() == 'w')
					{
						if (posY > 1)
							posY--;
					}
					if (Inputqueue->front() == 's')
					{
						if (posY < 19)
							posY++;
					}
					if (Inputqueue->front() == 'd' || Inputqueue->front() == 'l')
					{
						if (posX < 38)
							posX++;
					}
				}
				else
				{
					if (Inputqueue->front() == 'j')
					{
						if (posX > 11)
							posX--;
					}
					if (Inputqueue->front() == 'i')
					{
						if (posY > 1)
							posY--;
					}
					if (Inputqueue->front() == 'k')
					{
						if (posY < 19)
							posY++;
					}
					if (Inputqueue->front() == 'l')
					{
						if (posX < 38)
							posX++;
					}
				}
				
				Inputqueue->pop_front();
				position.posX = this->posX;
				position.posY = this->posY;
				PositionQueue.push_back(position);
			}

			mutex_cout.unlock();
			this_thread::sleep_for(chrono::milliseconds(50));
		}
	}
	~Player()
	{
	}
};

